#ifndef __SV2_VIDEO_BASE__
#define __SV2_VIDEO_BASE__

#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <queue>
#include <stack>
#include <thread>
#include "sms_core.h"
// #define X86_PLATFORM
// #define JETSON_PLATFORM


namespace sv2 {


class VideoWriterBase {
public:
  VideoWriterBase();
  ~VideoWriterBase();
  
  void setup(std::string file_path, cv::Size size, double fps=25.0, bool with_targets=false);
  void write(cv::Mat image, nlohmann::json tgts_json);
  void release();
  
  cv::Size getSize();
  double getFps();
  std::string getFilePath();
  bool isRunning();
protected:
  virtual bool setupImpl(std::string file_name_);
  virtual bool isOpenedImpl();
  virtual void writeImpl(cv::Mat img_);
  virtual void releaseImpl();
  void _init();
  void _run();
  
  bool _is_running;
  cv::Size _image_size;
  double _fps;
  bool _with_targets;  
  int _fid;
  int _fcnt;
  
  std::thread _tt;
  // cv::VideoWriter _writer;
  std::ofstream _targets_ofs;
  std::string _file_path;

  std::queue<cv::Mat> _image_to_write;
  std::queue<nlohmann::json> _tgts_to_write;
};

}
#endif
